package ngames.com.sushitv.base;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.TextView;

import ngames.com.sushitv.AppApplication;
import ngames.com.sushitv.R;
import ngames.com.sushitv.core.AppModel;
import ngames.com.sushitv.core.AppModelImpl;
import ngames.com.sushitv.tools.StackManager;

/**
 * Created by Administrator on 2016/2/24.
 */
public class BaseFragmentActivity extends FragmentActivity {
    protected AppApplication mAppApplication;
    protected AppModelImpl mAppModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getAppModel().setCurrentActivity(this);
        StackManager.getStackManager().pushActivity(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        getAppModel().setCurrentActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        StackManager.getStackManager().popActivity(this);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    public void onTitleBack(View v){
        finish();
    }

    public void setTitle(int resid){
        ((TextView) findViewById(R.id.txv_title)).setText(resid);
    }

    public AppApplication getAppApplication(){
        if (mAppApplication == null) {
            mAppApplication = (AppApplication) getApplication();
        }
        return mAppApplication;
    }

    public AppModel getAppModel(){
        if (mAppModel == null || mAppApplication == null) {
            mAppModel = (AppModelImpl) getAppApplication().getAppModel();
        }
        return mAppModel;
    }
}
